//
//  MeMessageViewCell.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/19.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "MeMessageViewCell.h"
#import <SDAutoLayout/SDAutoLayout.h>

@implementation MeMessageViewCell
{
    UILabel *lbtime;
    UILabel *lbtitle;
    UILabel *line;
    UILabel *lbcontent;
    UIView  *baseView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = COLOR_Background;
    }
    return self;
}

-(void)setup{
    lbtime = [UILabel new];
    lbtime.font = [UIFont systemFontOfSize:13];
    lbtime.textColor = UIColorFromRGB(0xFAFAFA);
    lbtime.backgroundColor = LCFromRGB(135, 135, 135);
    lbtime.textAlignment = NSTextAlignmentCenter;
    lbtime.layer.masksToBounds = YES;
    lbtime.layer.borderWidth = 1.0f;
    lbtime.layer.borderColor = [UIColor clearColor].CGColor;
    lbtime.layer.cornerRadius = 2.0f;
    
    lbtitle = [UILabel new];
    lbtitle.font =[UIFont systemFontOfSize:13];
    lbtitle.text =@"最新公告";
    lbtitle.textColor = UIColorFromRGB(0x333333);
    
    line = [UILabel new];
    line.backgroundColor =COLOR_Background;
    
    lbcontent = [UILabel new];
    lbcontent.font = [UIFont systemFontOfSize:13];
    lbcontent.textColor = UIColorFromRGB(0x666666);
    
    baseView = [UIView new];
    baseView.backgroundColor = [UIColor whiteColor];
    baseView.layer.masksToBounds = YES;
    baseView.layer.borderWidth = 1.0f;
    baseView.layer.borderColor = [UIColor whiteColor].CGColor;
    baseView.layer.cornerRadius = 6.0f;
    
    NSArray *views = @[baseView,lbtime];
    NSArray *views1 = @[lbtitle,line,lbcontent];
    [baseView sd_addSubviews:views1];
    [self.contentView sd_addSubviews:views];
    
    UIView *contentView = self.contentView;
    lbtime.sd_layout.heightIs(17).widthIs(150).topSpaceToView(contentView, 10).centerXEqualToView(contentView);
    baseView.sd_layout.topSpaceToView(lbtime, 10).leftSpaceToView(contentView, 15).rightSpaceToView(contentView, 15).bottomSpaceToView(contentView, 10);
    lbtitle.sd_layout.topSpaceToView(baseView, 10).heightIs(20).leftSpaceToView(baseView, 10).rightSpaceToView(baseView, 10);
    line.sd_layout.rightEqualToView(lbtitle).leftEqualToView(lbtitle).heightIs(1).topSpaceToView(lbtitle, 10);
    lbcontent.sd_layout.rightEqualToView(lbtitle).leftEqualToView(lbtitle).autoHeightRatio(0).topSpaceToView(line, 5);
}

-(void)setModel:(dataNewsInfo *)model
{
    dataNewsInfo *mm = [dataNewsInfo mj_objectWithKeyValues: model];
    
    NSTimeInterval interval    =[mm.createTime doubleValue] / 1000.0;
    NSDate *date  = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateString       = [formatter stringFromDate: date];
    lbtime.text = dateString;
    
    lbcontent.text = mm.content;
    lbtitle.text = mm.newsTitle;
    
    [self setupAutoHeightWithBottomView:lbcontent bottomMargin:10];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
